<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSDemo</title>
    <script src="https://cdn.bootcss.com/crypto-js/3.1.9-1/crypto-js.min.js"></script>
    <script src="../js/jsb.js"></script> 
    <script src="../js/jsencrpty.js"></script>
    <style>
        textarea {
            min-width: 380px;
            min-height: 180px;
        }
    </style>
</head>

<body>
    <p>
    <div class="leftBar">
        <div class="title">明文:</div>
        <textarea id="msg_source" placeholder="example"></textarea>
        <!-- <textarea name="message" id="msg_source" value="this is a example"
            onfocus="if(this.value=='this is a example'){this.value='';};this.select();"
            onblur="(this.value=='')?this.value='this is a example':this.value;" class="text_source">this is a example</textarea> -->
    </div>
    </p>
    <p>
    <div align="left">
        <!-- <input type="submit" name="Submit" value="提 交"> -->
        <button id="submit" , onclick="myFunction()">提交</button>
        <button id="download" , onclick="funDownload()">下载</button>
    </div>
    </p>
    <p>
    <div class="rightBar">
        <div class="title">密文:</div>
        <textarea name="cipher" id="encrypt_result" onclick="this.focus();this.select();"></textarea>
    </div>
    </p>
    <script>
        function myFunction() {
            var srta = document.getElementById("msg_source");
            var cnt = srta.value;
            var digest = CryptoJS.MD5(cnt, { asString: true });
            document.getElementById("encrypt_result").innerHTML = digest;
            console.log('log=>', cnt)
        };
        var funDownload = function () {
            // 创建隐藏的可下载链接
            var eleLink = document.createElement('a');
            eleLink.download = 'filename.txt';
            eleLink.style.display = 'none';
            var content = 'funDownloadfunDownloadfunDownload'
            // 字符内容转变成blob地址
            var blob = new Blob([content]);
            eleLink.href = URL.createObjectURL(blob);
            // 触发点击
            document.body.appendChild(eleLink);
            eleLink.click();
            // 然后移除
            document.body.removeChild(eleLink);
        };
        !(function(){
            key = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDjb4V7EidX/ym28t2ybo0U6t0n\n6p4ej8VjqKHg100va6jkNbNTrLQqMCQCAYtXMXXp2Fwkk6WR+12N9zknLjf+C9sx\n/+l48mjUU8RqahiFD1XT/u2e0m2EN029OhCgkHx3Fc/KlFSIbak93EH/XlYis0w+\nXl69GV6klzgxW6d2xQIDAQAB\n-----END PUBLIC KEY-----\n",
            hash = "0f7661ebd4d50fa2",
            e ="234";
            // a ="m+ydnPRmH7bj4735GzpCnXLRV3Ik4OLE6u/EgQPug7+P78kQYdCvoEX/GmDLswszlMyT12OsNGC9mHB2HtvZFWkg+jUVEGUc3+wScWRWAS8fF5XvCNILZpVhP66YEc8pP0PafFBnlUQki8qCKkfnROMTqYU+w+hB+JK1oZ5axSk=";
            var n = new JSEncrypt;
            n.setPublicKey(key);
            var a = n.encrypt(hash + e);
            console.log(a);
        })()
    </script>
</body>

</html>